package dao.impl;

import dao.BaseDao;
import dao.RegisterDao;

import java.sql.*;

public class RegisterDaoimpl extends BaseDao implements RegisterDao {

    @Override
    public int Register(String username, String password, String phone,String role, String sex, String facePhoto)
            throws SQLException, ClassNotFoundException {
        getConnection();
        PreparedStatement pst = null;
        try {
            String sql = "INSERT INTO users (username, password, role, phone, sex, facePhoto) VALUES (?, ?, ?, ?, ?, ?)";
            pst = conn.prepareStatement(sql);
            pst.setString(1, username);
            pst.setString(2, password);
            pst.setString(3, role);
            pst.setString(4, phone);
            pst.setString(5, sex);
            pst.setString(6, facePhoto);
            return pst.executeUpdate();
        } finally {
            if (pst != null) pst.close();
            if (conn != null) conn.close();
        }
    }

    @Override
    public boolean studentAdd(String name, String gender, String facePhoto)
            throws SQLException, ClassNotFoundException {
       getConnection();
        PreparedStatement pr = null;

        try {

            String sql = "INSERT INTO students (name, gender, facePhoto) VALUES (?, ?, ?)";
            pr = conn.prepareStatement(sql);
            pr.setString(1, name);
            pr.setString(2, gender);
            pr.setString(3, facePhoto);
            return pr.executeUpdate() > 0;
        } finally {
            if (pr != null) pr.close();
            if (conn != null) conn.close();
        }
    }
}